package com.cy.pj.common.util;


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class VarParam {
    public static void main(String[] args) {
        sum(1,1,2,2,3,1,4);
        int[] nums = new int[]{1,1,2,2,3,1,4};
        sum(nums);
    }

    // 可变参数只能应用于方法参数的最后一个参数
    static void sum(int... nums){ // 可变参数可以理解为一个特殊的数组
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        System.out.println(sum);
    }

    void input(){
        System.out.println("请输入数学计算公式");
        String equation = new Scanner(System.in).nextLine();
        String symbol = " ";
    }
    void split(String equation){
        List<String> list = new ArrayList<>();
        if (equation.contains("")){

        }
    }

    void count(String symbol,String... nums){
        int sum = 0;
        if (symbol.contains("+")){
            for (int i = 0; i < nums.length; i++) {
                sum += Double.parseDouble(nums[i]);
            }
        }
        if (symbol.contains("-")){
            for (int i = 0; i < nums.length; i++) {
                sum -= Double.parseDouble(nums[i]);
            }
        }
        if (symbol.contains("*")){
            for (int i = 0; i < nums.length; i++) {
                sum *= Double.parseDouble(nums[i]);
            }
        }
        if (symbol.contains("/")){
            for (int i = 0; i < nums.length; i++) {
                sum /= Double.parseDouble(nums[i]);
            }
        }
    }

}
